import { request } from "./request"


//请求列表数据
export function getuserlist(query, pagenum, pagesize) {
    return request({
        url: "/users",
        params: {
            query,
            pagenum,
            pagesize
        },
    })
}

//查询用户信息  get方式
export function getuserid(id) {
    return request({
        method: "get",
        url: `users/${id}`,
        params: {
            id
        }
    })
}

//分配用户角色
export function setrole(id, rid) {
    return request({
        method: "put",
        url: `users/${id}/role`,
        data: {
            rid
        }
    })
}


//添加用户  这是post传值  传递参数用data 不是params
export function getusername(form) {
    return request({
        method: "POST",
        url: "/users",
        data: {
            username: form.username,
            password: form.password,
            email: form.email,
            mobile: form.mobile
        },
    })
}

//删除用户  delete 方式
export function deleteuser(id) {
    console.log(id)
    return request({
        method: "delete",
        // 使用模板字符串要用`反引号
        url: `users/${id}`,

    })
}

// 编辑用户信息  put方式
export function edituser(id, editform) {
    return request({
        method: "put",
        url: `users/${id}`,
        data: {
            id: editform.newid,
            email: editform.email,
            mobile: editform.mobile
        }
    })
}

//获取角色列表
export function getroles() {
    return request({
        url: "/roles",
        method: "get"
    })
}